package chapter06

object Test14_TraitMixin {
  def main(args: Array[String]): Unit = {
    val student = new Student14
    student.study()
    student.increase()
    student.play()
    student.increase()
    new Student14 with Talent {
      override def sing(): Unit = println("student is good at singing")
    }.sing()
  }
}

//定义一个特质
trait Knowledge {
  var amount: Int = 0

  def increase(): Unit
}

trait Talent {
  def sing(): Unit
}

//定义一个特质
trait Young14 {
  //声明抽象和非抽象属性
  var age: Int
  val name: String = "young"

  def play(): Unit = {
    println("young people is playing")
  }

  def dating(): Unit
}

class Student14 extends Person13 with Young14 with Knowledge {
  //重写冲突的属性

  override val name: String = "bob"

  //实现抽象方法
  override def dating(): Unit = println(s"student $name is dating")

  def study(): Unit = println(s"student $name is studying ")

  override def sayHello(): Unit = {
    println(" student hello from: " + name)
  }

  override def increase(): Unit = {
    amount += 1
    println(s"amount is $amount")
  }
}